<?php
//$conn = odbc_connect ($DSN, "", "");
//$conn = mysql_connect("localhost", "Alexey", "12345") or die ("Could not connect");
$conn = mysql_connect("localhost", "root", "") or die ("Could not connect");
//$conn = mysql_connect("192.168.0.101", "michael", "12345") or die ("Could not connect");
mysql_select_db ("webdeso2")
    or die ("Could not select database");

function odbcFetch($res) {
  $row = array();
  $result = array();
  if ($result = mysql_fetch_array($res)) {
        while(list($field_name, $field_value) = each($result)) {
          //echo "name:".$field_name." value:".$field_value."end";
      $row[$field_name] = $field_value;
        }
  }
  return $row;

/*  if ($result = mysql_fetch_array($res)) {
    $nf = mysql_num_fields($res) + 1;
    for($count = 1; $count < $nf; $count++) {
      //$field_name = mysql_field_name($res, $count);
      //$field_value = mysql_result($res, $count);
      $row[$field_name] = $field_value;
    }
    return $row;
  }*/
}

function getData($SQL, &$data) {
  global $conn;
  $SQL = str_replace("]", "", str_replace("[", "", $SQL));
  $ret1 = mysql_query ($SQL)
        or die ("Query error: ".$SQL);
  if ($data = odbcFetch($ret1)) {
    $data["text"] = htmlspecialchars($data["text"]);
    return 1;
  }
  else {
    return -1;
  }
}

function getMultData($SQL, &$data) {
  global $conn;
  $SQL = str_replace("]", "", str_replace("[", "", $SQL));
  $ret_code = 0;
  $ret1 = mysql_query($SQL);
  //echo "r".$ret1."r1"."sql".$SQL."sql1";
  while ($row = odbcFetch($ret1)) {
    //echo "a".$ret_code."c".count($row)."/c";
    $data[$ret_code] = $row;
    $data[$ret_code]["text"] = htmlspecialchars($data[$ret_code]["text"]);
    $ret_code++;
  }
  return $ret_code;
}

function insertRecord($SQL) {
  global $conn;
  $SQL = str_replace("]", "", str_replace("[", "", $SQL));
  $ret1 = mysql_query($SQL)
        or die ("Query error: ".$SQL);
}

function GetPreviousInsertedID(){
    return mysql_insert_id();
}
?>